home *** CD-ROM | disk | FTP | other *** search
/ APDL Eductation Resources / APDL Eductation Resources.iso / programs / electronic / rlab / TestMatrix / cycol_r < prev    next >
Encoding:
Text File  |  1994-12-20  |  1.2 KB  |  44 lines

  1. //-------------------------------------------------------------------//
  2.  
  3. // Synopsis:    Matrix whose columns repeat cyclically.
  4.  
  5. // Syntax:    A = cycol ( [M, N] , K ) 
  6.  
  7. // Descriptioin:
  8.  
  9. //    A is an M-by-N matrix of the form A = B[1:M;1:N] where 
  10. //    B = [C, C, C,...] and C = RAND(M, K) (normal
  11. //    distribution). Thus A's columns repeat cyclically, and A has
  12. //    rank at most K.   K need not divide N. K defaults to
  13. //    ROUND(N/4). CYCOL(N, K), where N is a scalar, is 
  14. //    the same as CYCOL([N, N], K). 
  15.  
  16. //      This type of matrix can lead to underflow problems for Gaussian
  17. //      elimination: see NA Digest Volume 89, Issue 3 (January 22, 1989).
  18.  
  19. //    This file is a translation of cycol.m from version 2.0 of
  20. //    "The Test Matrix Toolbox for Matlab", described in Numerical
  21. //    Analysis Report No. 237, December 1993, by N. J. Higham.
  22.  
  23. //-------------------------------------------------------------------//
  24.  
  25. cycol = function ( n , k )
  26. {
  27.   local (n, k)
  28.  
  29.   m = n[1];        // Parameter n specifies dimension: m-by-n.
  30.   n = n[max(size(n))];
  31.  
  32.   if (!exist (k)) { k = max(round(n/4),1); }
  33.  
  34.   rand("normal", 0, 1);
  35.   A = rand(m, k);
  36.   for (i in 2:ceil(n/k))
  37.   {
  38.     A = [A, A[;1:k]];
  39.   }
  40.  
  41.   A = A[;1:n];
  42.   return A;
  43. };
  44.